package com.xxxy.jsq.action.course;

import com.xxxy.jsq.dao.CourseDao;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class deleteCourseServlet
 */
@WebServlet("/deleteCourseServlet")
public class deleteCourseServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public deleteCourseServlet() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        CourseDao dao = new CourseDao();

        // 获取页面传递的课程ID
        Long cid = Long.valueOf(request.getParameter("cid"));

        // 执行删除操作
        String flag = dao.deleteById(cid);

        // 返回操作结果
        PrintWriter out = response.getWriter();
        out.print(flag);
        out.flush();
        out.close();
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}